package com.anywhere.freightman.system.controller;

import com.anywhere.freightman.common.enumeration.WaybillType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("admin")
public class PageController {

    @GetMapping("reg")
    public String showRegPage() {
        return "admin/reg";
    }

    @GetMapping("home")
    public String showIndex() {
        return "admin/home";
    }

    @GetMapping("car")
    public String showCarPage() {
        return "admin/car/list";
    }

    @GetMapping("car/{id}")
    public String showCarDetailsPage(Model model,
                                     @PathVariable("id") Long id) {
        model.addAttribute("carId", id);
        return "admin/car/details";
    }

    @GetMapping("car/edit")
    public String showCarEditPage(@RequestParam(value = "id", required = false) Long carId, Model model) {
        model.addAttribute("carId", carId);
        return "admin/car/edit";
    }

    @GetMapping("driver")
    public String showDriverPage() {
        return "admin/driver/list";
    }

    @GetMapping("driver/{id}")
    public String showDriverDetailsPage(@PathVariable("id") Long id,
                                        Model model) {
        model.addAttribute("id", id);
        return "admin/driver/details";
    }

    @GetMapping("driver/edit")
    public String showDriverEditPage(@RequestParam(value = "driverId", required = false) String driverId, Model model) {
        if (!StringUtils.isEmpty(driverId)) {
            model.addAttribute("driverId", driverId);
        }
        return "admin/driver/edit";
    }

    @GetMapping("project")
    public String showProjectPage() {
        return "admin/project/list";
    }

    @GetMapping("project/{orderNo}")
    public String showProjectDetailsPage(@PathVariable("orderNo") String orderNo,
                                         Model model) {
        model.addAttribute("orderNo", orderNo);
        return "admin/project/details";
    }

    @GetMapping("project/edit")
    public String showProjectEditPage(@RequestParam(value = "type", required = false) WaybillType type, Model model) {
        model.addAttribute("type", type);
        return "admin/project/edit";
    }

    @GetMapping("invoice")
    public String showInvoicePage() {
        return "admin/invoice/list";
    }

    @GetMapping("company")
    public String showCompanyPage() {
        return "admin/company/list";
    }

    @GetMapping("company/{id}")
    public String showCompanyDetailsPage(Model model, @PathVariable("id") Long id) {
        model.addAttribute("companyId", id);
        return "admin/company/details";
    }

    @GetMapping("company/edit")
    public String showCompanyEditPage(@RequestParam(value = "id", required = false) Long companyId, Model model) {
        model.addAttribute("companyId", companyId);
        return "admin/company/edit";
    }


    @GetMapping("system")
    public String showSystemPage() {
        return "admin/system/account";
    }

    @GetMapping("system/role")
    public String showRolePage() {
        return "admin/system/role";
    }

    @GetMapping("system/dataset")
    public String showDatasetPage() {
        return "admin/system/dataset";
    }

    @GetMapping("member")
    public String showMemberPage(){
        return "admin/member/index";
    }

    @GetMapping("report/order")
    public String showReportPage(){
        return "admin/report/order";
    }


}
